package com.codejie.pms.controller;

import com.codejie.pms.entity.Customer;
import com.codejie.pms.entity.Staff;
import com.codejie.pms.entity.StaffKpi;
import com.codejie.pms.entity.User;
import com.codejie.pms.service.CustomerService;
import com.codejie.pms.service.StaffKpiService;
import com.codejie.pms.service.StaffService;
import com.codejie.pms.service.UserService;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 员工controller
 *
 *
 */
@RestController
@EnableAutoConfiguration
public class EmployeeController {
    private String a;
//    @Resource
//    private EmployeeService employeeService;

    @Resource
    private StaffKpiService staffKpiService;
    @Resource
    private UserService userService;
    @Resource
    private StaffService staffService;
    @Resource
    private CustomerService customerService;

    /**
     * Description 获取个人信息
     */
    @RequestMapping(value = "/employee/getMyName")
    public User getMyName(String userId) {
        a=userId;
        User user = new User();
        user.setUserId(userId);
        User user1 = userService.selectUser(user);
        return user1;
    }


    /**
     * Description 打开项目信息
     */
    @RequestMapping(value = "/employee/getMyPro", method = RequestMethod.GET)
    public ModelAndView getMyPro(String userId) {
        ModelAndView mv = new ModelAndView("my_pro");
        List<StaffKpi> staffKpiList = staffKpiService.getStaffKpiList(userId);
        System.out.println(staffKpiList);
        mv.addObject("staffKpi",staffKpiList);
        return mv;
    }


    /**
     * 项目批注
     */
//    @RequestMapping(value = "/advice/{advice}", method = RequestMethod.GET)
//
//    public ModelAndView advice(@PathVariable("advice")String advice) {
//
//        ModelAndView mv = new ModelAndView("getadvice");
//        System.out.println(advice);
//
//        mv.addObject("advice",advice);
//        return  mv;
//    }
    /**
     * 搜索
     *
     */
    @PostMapping("searchProject")
    public ModelAndView searchProject(String projectId){

        ModelAndView mv = new ModelAndView("my_pro");
        List<StaffKpi> staffKpiList = staffKpiService.getStaffKpiList2(projectId);
        mv.addObject("staffKpi",staffKpiList);
        return  mv;
    }

    /**
     * 搜索客户
     * @param
     * @return
     */

    @PostMapping("searchCustomer1")
    public ModelAndView searchCustomer(String customerName){

        ModelAndView mv = new ModelAndView("all_customer");
        System.out.println(customerName);
        Customer customer = customerService.getCustomerByName(customerName);
        mv.addObject("customer",customer);
        return  mv;
    }

    /**
     * Description 打开我的项目文件信息
     */
    @RequestMapping(value = "/employee/myKp", method = RequestMethod.GET)
    public ModelAndView myKp(String userId) {
        List<StaffKpi> staffKpiList = staffKpiService.getStaffKpiList(userId);

        Staff staff = staffService.getStaff(userId);
        String work = staff.getModelManager();
        ModelAndView mv = new ModelAndView("myKp");
        if (work == null) {
            return mv;
        }else if(work.equals("模型主管")){
            mv.setViewName("my_mx");
            mv.addObject("staffKpi", staffKpiList);
            return mv;
        }else if (work.equals("渲染主管")){
            mv.setViewName("my_xr");
            mv.addObject("staffKpi", staffKpiList);
            return mv;
        }else if(work.equals("后期主管")){
            mv.setViewName("my_hq");
            mv.addObject("staffKpi", staffKpiList);
            return mv;
        }else{
            return mv;
        }
    }


    /**
     * Description 获取客户信息
     */
    @RequestMapping(value = "/employee/getMyKh", method = RequestMethod.GET)
    public ModelAndView getMyKh(String userId) {
        ModelAndView mv = new ModelAndView("all_customer");
        List<StaffKpi>  staffKpi = staffKpiService.getStaffKpiList(userId);

        Staff staff = new Staff();
        Customer customer = new Customer();
        ArrayList<Customer> customers = new ArrayList<Customer>();
        int a = staffKpi.size();
        for (int i=0;i<a;i++){
            String projectid=staffKpi.get(i).getProjectId();
            customer =customerService.getCustomer2(projectid);
            customers.add(customer);
        }
        System.out.println(customers);
        mv.addObject("customer",customers);
        return mv;
    }

    /**
     * 客户详情
     *
     */
    @RequestMapping(value = "/customer_msg1/{customerId}", method = RequestMethod.GET)
    public ModelAndView customerMsg(@PathVariable("customerId")String customerId){
        ModelAndView mv = new ModelAndView("customer_msgs");
        Customer customer = customerService.getCustomer(customerId);
        mv.addObject("customer",customer);
        return  mv;
    }

    /**
      修改密码
     */
    @RequestMapping("/changeMyMsg")
    public ModelAndView changeMyMsg(User user) {
        System.out.println("safaf");
        ModelAndView mv = new ModelAndView("change_msg");
        mv.addObject("user",user);
        user.setUserId(a);
//        userService.updateUserPwd(user);
        return  mv;
    }


    /**
     * Description 获取个人信息
     */
    @RequestMapping(value = "/employee/getMyMsg",method = RequestMethod.GET)
    public ModelAndView getMyMsg(String userId) {
        System.out.println(userId);
        ModelAndView mv = new ModelAndView("mystaff_msg");
        User user = new User();
        Staff staff= staffService.getStaff(userId);
        mv.addObject("staff",staff);
        return mv;
    }
    /**
     * Description 修改密码
     */
    @RequestMapping(value = "/employee/change",method = RequestMethod.GET)
    public ModelAndView change(String userId) {

        ModelAndView mv = new ModelAndView("change_msgs");
        User user = new User();
        user.setUserId(userId);
        a=userId;
        mv.addObject("user",user);
        return  mv;
    }

}
